package com.example.blog.restController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blog.base.BaseImpl;
import com.example.blog.entity.MainMenu;
import com.example.blog.entity.Query;
import com.example.blog.service.MainMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class MenuController {

    @Autowired
    BaseImpl baseImpl;
    @Autowired
    MainMenuService mainMenuService;

    @GetMapping("/getMenuList")
    public Map<String, Object> getMenuList(Query query) {
        HashMap<String, Object> map = new HashMap<>();
        try {
//          protected List<T> records;查询到的数据
//          protected long total;总记录条数
//          protected long size;每页显示的条数
//          protected long current;当前页
//          protected boolean searchCount;总条数查询开启

            Page<MainMenu> listByQueryPage = baseImpl.getListByQueryPage(mainMenuService, query);
            List<MainMenu> mainMenuList = listByQueryPage.getRecords();
            map.put("code", 200);
            map.put("message", "获取成功！");
            map.put("data", mainMenuList);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", -1);
            map.put("message", "获取失败！");
        }
        return map;
    }
}
